'''
@author: philip
'''

from gear.models import user_item
from shop.models import item

class gear_repository:
    def __init__(self):
        pass
    
    def add_gear_for_user(self, user_id, item_id):
        new_item = user_item()
        new_item.user_id = user_id
        new_item.item_id = item_id
        new_item.save()
        return new_item
    
    def get_gear_for_user(self,user_id):
        user_items = user_item.objects.filter(user_id=user_id)
        r = []
        for ui in user_items:
            i = item.objects.get(id=int(ui.item_id))
            r.append({"name":i.name,"img":i.img})
        return r
